﻿@model ePrice.Models.Product
@{
    ViewBag.Title = "Product";
}

<h2>Product</h2>
@ViewBag.Id
@{
    // If one product is given
    if (!ViewBag.ListMode)
    {
        if (Model != null)      
        {
            <table> 
				<tr> 
					<th> 
						No. 
					</th> 
					<th> 
						Product ID 
					</th> 
					<th> 
						Product Name 
					</th> 
				</tr>
				<tr> 
					<td> 
						1
					</td> 
					<td> 
						@Model.ProductId
					</td> 
					<td> 
						@Model.ProductName
					</td> 
				</tr>
			</table>
			<br />
            Html.RenderAction("CommentPartial", new { id = Model.ProductId });
        }
        else 
        {
            <p>Error!</p>
            <p>No product was found on the server</p>
        }
    }
    // If product id is not given or invalid data, model is a list product
    else
    {
        
		int count = 1;
			<table> 
				<tr> 
					<th> 
						No. 
					</th> 
					<th> 
						Product ID 
					</th> 
					<th> 
						Product Name 
					</th> 
				</tr>
				@foreach(ePrice.Models.Product product in ViewBag.List) { 
				<tr> 
					<td> 
						@count
					</td> 
					<td> 
						@Html.DisplayFor(modelItem => product.ProductId) 
					</td> 
					<td> 
						@Html.DisplayFor(modelItem => product.ProductName) 
					</td> 
				</tr>
				count++;
				}
			</table>
			<br />
			
    }

	
}
